﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Scan.PDAService;
using Scan.Controls;

namespace Scan
{
    public partial class ReferPersonView : BaseView
    {
        // 人员数据
        private Person[] gPersons = null;
        public Person[] Persons
        {
            get { return gPersons; }
            set { gPersons = value; }
        }

        public ReferPersonView()
        {
            InitializeComponent();
            this.Title = "选择人员";

            // 往ListView添加可以排序的列
            this.SuspendLayout();
            this.ResumeLayout(false);
        }

        public override void OnLoad()
        {
            if (needClearView)
            {
                needClearView = false;
                lstData.Items.Clear();
                txtCode.Text = "";
                txtName.Text = "";
            }

            lstData.Focus();
            if (lstData.Items.Count > 0)
            {
                lstData.Items[0].Selected = true;
            }
        }

        protected override void FocusControl(bool forward)
        {

        }

        // 绑定表格数据
        public void DataBind(Person[] Persons)
        {
            lstData.Items.Clear();
            if (Persons != null && Persons.Length != 0)
            {
                foreach (Person Person in Persons)
                {
                 //   ListViewItem item = new ListViewItem(new string[] { Person.CPersonCode, Person.CPersonName, Person.CDepCode, Person.CPersonProp });
                   // lstData.Items.Add(item);
                }
            }
            else
            {
                MessageBox.Show("没有获取到人员数据！","参照选择");
            }
        }

        // 查找仓库
        public void Find(string PersonCode, string PersonName)
        {
            gPersons = ArchivesPersons.GetPersons(true, PersonCode, PersonName);
            DataBind(gPersons);
        }

        // 返回
        public override void Escape(object sender, EventArgs e)
        {
            this.ParentForm.LoadView(this.ResultView.GetType(), null, true, false);
        }

        // 确定，S2键
        public override void S2(object sender, EventArgs e)
        {
            int SelectIndex = 0;
            for (int i = 0; i < lstData.Items.Count; i++)
            {
                if (lstData.Items[i].Selected)
                {
                    SelectIndex = i;
                    break;
                }
            }
            this.ResultView.ReturnProc(true, ReferType.Person, gPersons[SelectIndex]);
            this.ParentForm.LoadView(this.ResultView.GetType(), null, true, false);
        }

        // 定位、过滤编码和名称
        private void txtName_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtCode_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
